/*
 * @Author: error: error: git config user.name & please set dead value or install git && error: git config user.email & please set dead value or install git & please set dead value or install git
 * @Date: 2023-08-14 13:30:04
 * @LastEditors: error: error: git config user.name & please set dead value or install git && error: git config user.email & please set dead value or install git & please set dead value or install git
 * @LastEditTime: 2023-08-14 14:19:27
 * @FilePath: \MashangqianWebByBank\src\utils\validate.js
 * @Description: 表单校验组件
 */
// 手机号码验证
const validatePhone = (rule, value, callback) => {
  const patter = new RegExp(
    "^1([358][0-9]|4[579]|66|7[0135678]|9[89])[0-9]{8}$"
  );
  if (!patter.test(value)) {
    return callback(new Error("请输入正确格式的手机号！"));
  } else {
    callback(); // 必须有此项回调，否则验证会一直不通过
  }
};
// 邮箱的正则
const validateEmail = (rule, value, callback) => {
  const mailbox = new RegExp(
    "^[a-zA-Z0-9_.-]+@[a-zA-Z0-9-]+(.[a-zA-Z0-9-]+)*.[a-zA-Z0-9]{2,6}$"
  );
  if (!mailbox.test(value)) {
    return callback(new Error("请输入正确格式的邮箱！"));
  } else {
    callback();
  }
};
// 身份证号
const validateIdCardNo = (rule, value, callback) => {
  const mailbox = new RegExp(
    "^[1-9]d{5}(18|19|([23]d))d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)d{3}[0-9Xx]$)|(^[1-9]d{5}d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)d{2}[0-9Xx]$"
  );
  if (!mailbox.test(value)) {
    return callback(new Error("请输入正确格式的身份证号！"));
  } else {
    callback();
  }
};
export default {
  common: {
    // ---------------------公共验证方法
    cPhone: [
      {
        // 手机号
        required: true,
        message: "请输入联系方式",
      },
      {
        validator: validatePhone,
        trigger: "blur",
      },
    ],
    email: [
      {
        // 邮箱
        required: true,
        message: "邮箱",
      },
      {
        validator: validateEmail,
        trigger: "blur",
      },
    ],
    idCardNo: [
      {
        // 身份证号码
        required: true,
        message: "身份证号码不能为空",
      },
      {
        validator: validateIdCardNo,
        trigger: "blur",
      },
    ],
  },
  handle: {
    // ---------------------处理表单的验证方法
    CompanyName: [
      {
        //商铺名称
        required: true,
        message: "请输入商铺名称",
      },
    ],
    cName: [
      {
        //买家姓名
        required: true,
        message: "请输入买家姓名",
      },
    ],
  },
};
